
<%@ page import = "clothing.database.Item" %>
<%@ page import = "java.util.ArrayList" %>
<%@page import = "clothing.database.ItemManager" %>
<%@ include file = "templates/header.jsp" %>

<%
String id =request.getParameter("id");
int iid = Integer.parseInt(id);
ItemManager im = new ItemManager();
Item editItem = im.getItem(iid);
String name = editItem.getName();
String color = editItem.getColor();
String size = editItem.getSize();
Double cost = editItem.getCost();
Double sp = editItem.getSalePrice();

%>


<h3> Edit Item Page </h3>

<script>
function process(a)
{
		document.getElementById('id').value=a;
		document.myform.submit();
}  
</script>
   
	
<h2> Edit an Item </h2>
<form name="myform" id="myform" action ="updateItem.jsp" method = "post" >
	<table>
		<tr>
            <td>Item ID</td>
            <% out.println("<td name=\"item_id\" value=\""+id+"\">"+id+"</td>"); %>
            
            
        </tr>
        <tr>
			<td>Name: </td>
            <td>
                   <select name="name" />
                 <% 
                 
                ArrayList<String> listNames = new ArrayList();
                 listNames.add(0, "T Shirt");
                 listNames.add(0, "Long Sleeve Shirt");
                 listNames.add(0, "No Sleeve Shirt");
                 listNames.add(0, "Sweater");
                 listNames.add(0, "Skirt");
                 listNames.add(0, "Shorts");
                 listNames.add(0, "Jeans");
                 
                 
                 
                for(int i=0;i<listNames.size();i++)
            	{
            		String current = listNames.get(i);
            		if(current.equals(name))
            	    {
            			out.println("<option selected=\"selected\" value=\""+name+"\">"+name+"</option>");
            		}
            		else{out.println("<option value=\""+current+"\">"+ current+"</option>");}
            	}           
                
                %>
                 </select>    
            </td>
		</tr>

		<tr>
			<td>Color: </td>
            <td>
                   <select name="color" />
                 <% 
                
                ArrayList<String> listColors = new ArrayList();
                 listColors.add(0, "White");
                 listColors.add(0, "Black");
                 listColors.add(0, "Yellow");
                 listColors.add(0, "Green");
                 listColors.add(0, "Purple");
                 listColors.add(0, "Red");
                 listColors.add(0, "Blue");
                 listColors.add(0, "Orange");
                 listColors.add(0, "Grey");
                 
                for(int i=0;i<listColors.size();i++)
            	{
            		String current = listColors.get(i);
            		if(current.equals(color))
            	    {
            			out.println("<option selected=\"selected\" value=\""+color+"\">"+color+"</option>");
            		}
            		else{out.println("<option value=\""+current+"\">"+ current+"</option>");}
            	}           
                
                %>
                 </select>    
            </td>
		</tr>

		<tr>
			<td>Size: </td>
            <td>
                   <select name="size" />
                 <% 
               
                ArrayList<String> listSizes = im.getListSizes();
                for(int i=0;i<listSizes.size();i++)
            	{
            		String current = listSizes.get(i);
            		if(current.equals(size))
            	    {
            			out.println("<option selected=\"selected\" value=\""+size+"\">"+size+"</option>");
            		}
            		else{out.println("<option value=\""+current+"\">"+ current+"</option>");}
            	}           
                
                %>
                 </select> 
                   
            </td>
		</tr>
		<tr>
			<td>Cost: </td>
            <td>
            <% out.println("<input type=\"text\" name=\"cost\" value=\""+cost+"\"/>");%>
            </td>
		</tr>
		<tr>
			<td>Sale Price: </td>
            <td>
            <% out.println("<input type=\"text\" name=\"sale_price\" value=\""+sp+"\"/>");%>
            </td>
		</tr>
		
		
		<tr>
			<td> </td><td><input type="submit" value= "submit" onclick = "process(<%= id %>);" /></td>
		</tr>
    <input type="hidden" name ="id" id = "id" />
	</table>
	</form>

<%@ include file = "templates/footer.jsp" %>


